How to fork and push content to the Github repository

We will adopt the fork and branch Git Workflow. The fork and branch workflow is a common way of collaborating on open source projects using Git and GitHub.

Basically, the fork and branch workflow looks something like this:

  • Fork a GitHub repository.
  • Clone the forked repository to your local system.
  • Add a Git remote for the original repository.
  • Create a feature branch in which to place your changes.
  • Make your changes to the new branch.
  • Commit the changes to the branch.
  • Push the branch to GitHub.
  • Open a pull request from the new branch to the original repo.
  • Clean up after your pull request is merged.

How to fork and clone the pythonclub repository

  1. Install Git in your computer and create an account in GitHub.

  2. Open the web browser and visit the link https://github.com/pucdata/pythonclub
    Click the icon Fork located in the top-right of the window

  3. Create a folder in your computer for storing all your Github repositories. We recommed creating the folder Github in your HOME. Open the terminal and execute the following commands.

    cd ~
    mkdir Github
    cd Github
    
  4. Setup a couple of Github parameters. Replace vim with your favorite editor, YOUR_NAME with your Name and YOUR_EMAIL with your email address

    git config credential.helper store
    git config --global core.editor "vim"
    git config --global push.default current
    git config --global user.name "YOUR_NAME"
    git config --global user.email "YOUR_EMAIL"
    
  5. Clone the pythonclub repository from the Github server to your local computer (origin). Replace YOUR_GITHUB_USERNAME with your Github username. Add a Git remote for the original repository (upstream).

    git clone https://github.com/YOUR_GITHUB_USERNAME/pythonclub.git  
    cd pythonclub  
    git remote add upstream https://github.com/pucdata/pythonclub.git  
    git fetch --all  
    git remote -v
    

How to create a new branch and push new content

  1. Let’s say you want to create a tutorial about astropy. The best way is to create a branch from master and develop the new code on that branch. Let’s call the branch astropy.

    git checkout -b astropy
    
  2. Now you are in the astropy branch and you can add any content you want. Even you can modify files that were already in the repository.

    For tracking the new files you need to use git add

    For commiting the changes you need to use git commit

    Replace TYPE_A_LOG_MESSAGE by a short message describing the changes

    git add -A
    git commit -m "TYPE_A_LOG_MESSAGE"
    
  3. Push the changes to your forked copy of the repository (it's called origin). Since you are pushing content for the first time, you need to specify where are you pushing. In this case, we are pushing to the astropy branch hosted in the remote origin.

    git push --set-upstream origin astropy
    

    The next time you push content to the repository you just need to execute git push

    git push
    

How to open a pull-request

The previous instructions were for forking the pythonclub reposotiory and pushing new content to the forked repository (YOUR_GITHUB_USERNAME). Now you will open a pull-request to push the content to the original repository (pucdata)

  1. The easiest way is visiting the forked repository in your Github account (https://github.com/YOUR_GITHUB_USERNAME/pythonclub) and clicking the green button Compare & pull request

A new window will be opened and you should type a title and comment for the pull-request. This information will be read by the manager of pucdata, so try to be concise and clear. Once you are done, click the green button Create pull request.

How to keep the master synced with the original repository (upstream)

The most important branch in your repository is called master. You should reserve this branch to have an identical copy of the master branch in the original repository (https://github.com/pucdata/pythonclub). For adding new content or modifying code, you should always create a new branch, let's say astropy.

To keep synced the master branch in your forked repository with the original repository, execute the following commands

git checkout master
git fetch upstream
git rebase upstream/master
git push

How to reset the master and restart from the original repository (upstream)

git checkout master
git fetch upstream
git reset --hard upstream/master  
git push origin master --force

How to upload large files (larger than 100 MB)

Download and install git-lfs from https://git-lfs.github.com

Track all the FITS files with git-lfs

git lfs track

Add a large FITS file to the repository

git add DR9Q.fits
git commit -am "Added SDSS DR9 Quasar catalog"
git push

How to delete branches

Delete a local branch

git branch -d <branch>

Delete a remote branch:

git push origin --delete <branch>

Delete a local remote-tracking branch

git branch -dr <remote>/<branch> # Shorter

How to do pull-request from the terminal

Download and install hub, a command-line wrapper for git that makes you better at GitHub. Read the guide https://hub.github.com

Visit the link and download the corresponding compiled binary https://github.com/github/hub/releases

git commit -am "Added SDSS DR9 Quasar catalog"
git push
git pull-request

Additional information

If you want to learn more details about Git, Github and the Fork-and-Branch workflow, please visit the following links


In [ ]: